<?php

declare (strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace App\Model;

class Trade extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected ?string $table = 'trade';
    public static $statusList = [1 => '启用', -1 => '禁用'];
    public function manager()
    {
        return $this->belongsTo(Manager::class, 'manager_id');
    }
    public function getStatusTextAttribute()
    {
        return static::$statusList[$this->status] ?? '禁用';
    }
    public function scopeActive($q)
    {
        return $q->where('status', 1);
    }
    /**
     * 接口返回
     * @return array
     */
    public function toApi()
    {
        return ['id' => $this->id, 'name' => $this->name ?? ''];
    }
}